gl: Glyph cache fixes
authorMatthias Clasen <mclasen@redhat.com>
Wed, 31 Jul 2019 02:21:52 +0000 (22:21 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Wed, 31 Jul 2019 04:03:13 +0000 (00:03 -0400)
Pass the full location to the glyph cache lookup,
and use the same rounding as cairo does. This makes
the output much closer to the cairo renderer.

gsk/gl/gskglglyphcache.c
gsk/gl/gskglglyphcacheprivate.h
gsk/gl/gskglrenderer.c

index a33a1357aa88f1ef9b8e35e43f3c69a36589827e..ff87229b56aa13b8422b16df4898f7c9928aa09b 100644 (file)
@@ -237,7 +237,7 @@ add_to_cache (GskGLGlyphCache  *self,
       value->texture_id = gsk_gl_driver_create_texture (driver, width, height);
 
       gsk_gl_driver_bind_source_texture (driver, value->texture_id);
-      gsk_gl_driver_init_texture_empty (driver, value->texture_id, GL_NEAREST, GL_NEAREST);
+      gsk_gl_driver_init_texture_empty (driver, value->texture_id, GL_LINEAR, GL_LINEAR);
 
       value->tx = 0.0f;
       value->ty = 0.0f;
@@ -245,18 +245,17 @@ add_to_cache (GskGLGlyphCache  *self,
       value->th = 1.0f;
     }
 
-
   upload_glyph (key, value);
 }
 
-#define PHASE(x) ((x % PANGO_SCALE) * 4 / PANGO_SCALE)
+#define PHASE(x) ((int)(floor (4 * (x + 0.125)) - 4 * floor (x + 0.125)))
 
 gboolean
 gsk_gl_glyph_cache_lookup (GskGLGlyphCache  *cache,
                            PangoFont        *font,
                            PangoGlyph        glyph,
-                           int               x,
-                           int               y,
+                           float             x,
+                           float             y,
                            float             scale,
                            GskGLDriver      *driver,
                            GskGLCachedGlyph *cached_glyph_out)
@@ -264,6 +263,7 @@ gsk_gl_glyph_cache_lookup (GskGLGlyphCache  *cache,
   GskGLCachedGlyph *value;
   guint xshift = PHASE (x);
   guint yshift = PHASE (y);
+  const guint key_scale = (guint)(scale * 1024);
 
   value = g_hash_table_lookup (cache->hash_table,
                                &(GlyphCacheKey) {
@@ -271,7 +271,7 @@ gsk_gl_glyph_cache_lookup (GskGLGlyphCache  *cache,
                                  .glyph = glyph,
                                  .xshift = xshift,
                                  .yshift = yshift,
-                                 .scale = (guint)(scale * 1024)
+                                 .scale = key_scale
                                });
 
   if (value)
@@ -298,7 +298,6 @@ gsk_gl_glyph_cache_lookup (GskGLGlyphCache  *cache,
     {
       GlyphCacheKey *key;
       PangoRectangle ink_rect;
-      const guint key_scale = (guint)(scale * 1024);
 
       pango_font_get_glyph_extents (font, glyph, &ink_rect, NULL);
       pango_extents_to_pixels (&ink_rect, NULL);
@@ -322,11 +321,11 @@ gsk_gl_glyph_cache_lookup (GskGLGlyphCache  *cache,
       key->glyph = glyph;
       key->xshift = xshift;
       key->yshift = yshift;
-      key->scale =  key_scale;
+      key->scale = key_scale;
 
       if (key->scale > 0 &&
-          ink_rect.width * key->scale > 0 &&
-          ink_rect.height * key->scale > 0)
+          value->draw_width * key->scale / 1024 > 0 &&
+          value->draw_height * key->scale / 1024 > 0)
         add_to_cache (cache, key, driver, value);
 
       *cached_glyph_out = *value;
index 085979890710f7cc4248ba4628c088463b94683c..ee1912c3a6a8e54aa3803315a01c15a89919f40f 100644 (file)
@@ -57,8 +57,8 @@ void                     gsk_gl_glyph_cache_begin_frame     (GskGLGlyphCache
 gboolean                 gsk_gl_glyph_cache_lookup          (GskGLGlyphCache        *self,
                                                              PangoFont              *font,
                                                              PangoGlyph              glyph,
-                                                             int                     x,
-                                                             int                     y,
+                                                             float                   x,
+                                                             float                   y,
                                                              float                   scale,
                                                              GskGLDriver            *driver,
                                                              GskGLCachedGlyph       *cached_glyph_out);
index b2fee7872f869d6a799a34eb5838c5d6704168dc..cced23aa9b949b5d3fdf4547bb58c4701559bd57 100644 (file)
@@ -592,11 +592,14 @@ render_text_node (GskGLRenderer   *self,
       if (gi->glyph == PANGO_GLYPH_EMPTY)
         continue;
 
+      cx = (double)(x_position + gi->geometry.x_offset) / PANGO_SCALE;
+      cy = (double)(gi->geometry.y_offset) / PANGO_SCALE;
+
       gsk_gl_glyph_cache_lookup (self->glyph_cache,
                                  (PangoFont *)font,
                                  gi->glyph,
-                                 x * PANGO_SCALE + x_position + gi->geometry.x_offset,
-+                                y * PANGO_SCALE + gi->geometry.y_offset,
+                                 x + cx,
++                                y + cy,
                                  text_scale,
                                  self->gl_driver,
                                  &glyph);
@@ -608,9 +611,6 @@ render_text_node (GskGLRenderer   *self,
       if (glyph.texture_id == 0)
         goto next;
 
-      cx = (x_position + gi->geometry.x_offset) / PANGO_SCALE;
-      cy = gi->geometry.y_offset / PANGO_SCALE;
-
       ops_set_texture (builder, glyph.texture_id);
 
       tx  = glyph.tx;
@@ -618,8 +618,8 @@ render_text_node (GskGLRenderer   *self,
       tx2 = tx + glyph.tw;
       ty2 = ty + glyph.th;
 
-      glyph_x = x + cx + glyph.draw_x;
-      glyph_y = y + cy + glyph.draw_y;
+      glyph_x = floor (x + cx + 0.125) + glyph.draw_x;
+      glyph_y = floor (y + cy + 0.125) + glyph.draw_y;
       glyph_w = glyph.draw_width;
       glyph_h = glyph.draw_height;